﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace _2023_5_15简单记事本
{
    public partial class NoteBook : Form
    {
        public NoteBook()
        {
            InitializeComponent();
        }

        private void changeline_Click(object sender, EventArgs e)
        {
            if(changeline.Text=="是否自动换行")
            {
                textBox1.WordWrap = true;
                changeline.Text = "是否不自动换行";
            }
            else
            {
                textBox1.WordWrap = false;
                changeline.Text = "是否自动换行";
            }

        }

        private void save_Click(object sender, EventArgs e)
        {
            using (FileStream file = new FileStream(@"C:\Users\86198\Desktop\tset.txt", FileMode.OpenOrCreate, FileAccess.Write))
            {
                file.Seek(0, SeekOrigin.Begin);
                file.SetLength(0);
                int count = 0;
                byte[] arr = Encoding.Default.GetBytes(textBox1.Text.Trim());
                file.Write(arr, 0, arr.Length);
            }
                

            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (FileStream file = new FileStream(@"C:\Users\86198\Desktop\tset.txt", FileMode.OpenOrCreate, FileAccess.Read))
            {
                int count = 0;
                byte[] arr = new byte[30];

                while (true)
                {
                     count= file.Read(arr, 0, 30);
                    textBox1.Text += Encoding.Default.GetString(arr,0,count);
                    if (count<30)
                    {
                        break;
                    }
                   

                }
                
            }
        }
    }
}
